#博客首页测试用例
import time

from selenium.webdriver.common.by import By

from common.Utils import BlogDriver
#博客首页测试用例
class BlogList:
    url=""
    driver=""
    def __init__(self):
        self.url = "http://8.137.19.140:9090/blog_list.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)
    #测试首页（登录情况下）
    def ListTestByLogin(self):
        #测试博客标题是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.title")
        #测试博客内容是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > div.desc")
        #测试博客按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.right > div:nth-child(1) > a")
        #个人信息-检查昵称是否存在
        self.driver.find_element(By.CSS_SELECTOR,"body > div.container > div.left > div > h3")

        time.sleep(2)
        # 检查博客数量是否为0
        text = self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(5)").text
        print(text)
        # 断言 -- 如果元素不为0，即测试通过
        assert text != "0"

        #添加屏幕截图
        BlogDriver.getScreenShot()

    #测试首页(未登录情况下)
    def NotLoginListTest(self):
        self.driver.back()
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        text = self.driver.find_element("body > div.container > div.right > div:nth-child(1) > div.title").text()
